package deom1;

import java.util.List;

class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) {
        this.val = val;
    }
    ListNode(int val, ListNode next) {
        this.val = val; this.next = next;
    }
}
public class Test1 {

}


class Solution {
    public ListNode removeElements(ListNode head, int val) {
        ListNode dehead = new ListNode(0);
        dehead.next = head;
        ListNode ret = dehead;
        while (ret.next != null) {
            if (ret.next.val == val) {
                ret.next = ret.next.next;
            } else {
                ret = ret.next;
            }
        }
        return dehead.next;

    }
}

class Solution1 {
    public ListNode reverseList(ListNode head) {
        if (head == null) return null;
        ListNode ret = head.next;
        head.next = null;
        while (ret != null) {
            ListNode retN = ret.next;
            ret.next = head;
            head = ret;
            ret = retN;
        }
        return head;
    }
}

